<html>
	<head>

		<script type="text/javascript">

		function findSubstring(text,searchTerm)
		{
			text = text.toLowerCase();
			searchTerm = searchTerm.toLowerCase();
			if (text.indexOf(searchTerm,0) === -1) 
				{
					return 0;
				}
			else 
			{
				var counter = 1;
				var nextPosition = text.indexOf(searchTerm,0);
				var holder = parseInt(nextPosition)+1;
				while (nextPosition !== -1)
				{
					nextPosition = text.indexOf(searchTerm,holder);
					if (nextPosition !== -1)
					 {
					 	counter++;
					 	holder = parseInt(nextPosition)+1;
					 };
				};
				return counter;
			};
		};

		function onClick()
		{
			  var text = "We are living in an yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days."
		      window.alert(findSubstring(text,"in")+" times")
		};
		</script>
		<title></title>
	</head>
	<body>
		
		
		<pre>
	Text: We are living in an yellow submarine. 
	We don't have anything else. Inside the submarine is very tight. 
	So we are drinking all the day. We will move out of it in 5 days.
	SearchTerm: in
		</pre>
		<button onclick="onClick()" id="buttonOne">Find SearchTerm</button>
		
	</body>
</html>